def close():
    print("0")
x=int(input())
max=0
x1=0
yui=0
n1=0
n2=0
n3=0
n4=0
n5=0
n6=0
n7=0
n8=0
n9=0
n10=0
n11=0
n12=0
n13=0
n14=0
n15=0
if x<999 or x>9999:
    close()
else:
    d=x//10
    c=x//100
    g=x//1000
    d1=x%10
    d2=x%100
    d3=x%1000
    a1=d%10
    a2=d%100
    a3=c%10
    x1=a3*100+a1*10+d1
    x2 = g * 100 + a3 * 10 + a1
    x3 = g * 100 + a3 * 10 + d1
    x4 = g * 0 + a3 *10 +d1
    x5 = g * 0 + g * 10 + a1
    x6 = g * 0 + g * 10 + a3
    x7 = g * 0 + a3 * 10 + a1
    x8 = g * 0 + a1 * 10 + d1
    x9 = g * 100 + a1 * 10 + d1
    f1 = g * 0 + g * 10 + d1
    x=x
    count=0
    for i in range (1,x+1):
        if x%i == 0:
            count+=1
    if count==2:
        yui=yui+1
        n1=x
    x = g
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        yui = yui + 1
        n2=x
    x = a3
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        yui = yui + 1
        n3 = x
    x = a1
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        yui = yui + 1
        n4 = x
    x = d1
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n5 = x
        yui = yui + 1
    x = x1
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n6 = x
        yui = yui + 1
    x = x2
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        yui = yui + 1
        n7 = x
    x = x3
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n8 = x
        yui = yui + 1
    x = x4
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n9 = x
        yui = yui + 1
    x = x5
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n10 = x
        yui = yui + 1
    x = x6
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n11 = x
        yui = yui + 1
    x = x7
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n12 = x
        yui = yui + 1
    x = x8
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n2 = x
        yui = yui + 1
    x = x9
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n13 = x
        yui = yui + 1
    x = f1
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1
    if count == 2:
        n14 = x
        yui=yui+1
    if max<n1:
        max=n1
    if max<n2:
        max=n2
    if max<n3:
        max=n3
    if max<n4:
        max=n4
    if max<n5:
        max=n5
    if max<n6:
        max=n6
    if max<n7:
        max=n7
    if max<n8:
        max=n8
    if max<n9:
        max=n9
    if max<n10:
        max=n10
    if max<n11:
        max=n11
    if max<n12:
        max=n12
    if max<n13:
        max=n13
    if max<n14:
        max=n14
    print(max)

